'use strict';

/**
 * @name UpdateSystemCtrl
 * @author ZYF
 */

angular.module('metalabOperationApp').controller('UpdateSystemCtrl', ['$scope', '$rootScope', '$state', '$stateParams', 'MetaResources', 'MetaRemind', 'MetaUtils', function($scope, $rootScope, $state, $stateParams, MetaResources, MetaRemind, MetaUtils) {
    $scope.editCtrl = {
        data: []
    };
    $scope.getEditData = function() {
        MetaResources.update.query({
                '_sort': '-created_at',
                'tag': '更新日志'
            },
            function(data) {
                if (data.length) {
                    $scope.editCtrl.data = data;
                }
            },
            function(error) {
                MetaRemind.serverError(error);
            });
    };

    $scope.init = function() {
        $scope.openModel = MetaUtils.openModel;
        $scope.getEditData();
    };

    $scope.delete = function(id) {
        if (confirm('确认删除')) {
            MetaResources.update.delete({
                id: id
            }, function() {
                MetaRemind.success('删除成功');
                $state.reload();
            }, function(error) {
                MetaRemind.error(error);
            });
        }
    };

    $scope.toBeContinued = MetaRemind.error;
    $scope.init();
}]);
